package com.qinghe.pro.service.main.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qinghe.pro.entity.main.Suggest;
import com.qinghe.pro.mapper.main.SuggestMapper;
import com.qinghe.pro.service.main.SuggestService;
import com.qinghe.utils.Page;

@Service("suggestServiceImpl")
public class SuggestServiceImpl implements SuggestService {

	@Autowired
	private SuggestMapper suggestMapper;

	@Override
	public Suggest get(Integer id) {
		return suggestMapper.selectByPrimaryKey(id);
	}

	@Override
	public void insert(Suggest suggest) {
		suggestMapper.insertSelective(suggest);
	}

	@Override
	public void delete(Integer id) {
		suggestMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Suggest> findByPage(Page page) {
		PageHelper.startPage(page.getPageNum(), page.getNumPerPage()).setOrderBy("create_time desc");
		List<Suggest> list = suggestMapper.selectAll();
		PageInfo<Suggest> p = new PageInfo<Suggest>(list);
		page.setTotalCount((int) p.getTotal());
		return list;
	}

}
